package com.jiang.controller;

import com.jiang.dao.userimpl;
import com.jiang.entity.User;
import com.jiang.service.Administratorimpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.jiang.controller
 * @Description:
 * @Date 2022/5/20 22:05
 */
@WebServlet("/admin")
public class AdminController extends BaseServlet {
    //管理员登录
    public String login(HttpServletRequest request, HttpServletResponse response) {
        //获取参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //判断用户名和密码是否为空
        if(username ==null || password==null || username==""|| password==""){
            return "redirect:"+request.getContextPath()+"admin/login.jsp";
        }
        Administratorimpl anmin = new Administratorimpl(new userimpl());

        User user = anmin.selectAdmin(username, password);
        if(user!=null){
            request.getSession().setAttribute("admin",user);
            return "redirect:" +request.getContextPath()+"/admin/admin.jsp";
        }else{
            return "redirect:" +request.getContextPath()+"/admin/login.jsp";
        }
        //查询用户是否存在

    }
}